package com.yqg.manage.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yqg.manage.common.interceptor.SysLog;
import com.yqg.manage.mapper.RecordOperateMapper;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yqg.manage.common.Result;

import com.yqg.manage.service.IRecordOperateService;
import com.yqg.manage.entity.RecordOperate;

import org.springframework.web.bind.annotation.RestController;

/**
 * RecordOperateController 前端控制器
 * @author zxf
 * @since 2025-09-16
 */
@RestController
@RequestMapping("/record-operate")
public class RecordOperateController {

    @Resource
    private IRecordOperateService recordOperateService;

    @Resource
    private RecordOperateMapper recordOperateMapper;

    /**
    *  新增或者更新
    */
    @PostMapping("/edit")
    public Result save(@RequestBody RecordOperate recordOperate) {
        return Result.success(recordOperateService.saveOrUpdate(recordOperate));
    }
    /**
    *  删除
    */
    @GetMapping("delete/{id}")
    @SysLog("删除操作记录")
    public Result delete(@PathVariable Integer id) {
        RecordOperate recordOperate =recordOperateService.getById(id);
        return Result.success(recordOperateService.saveOrUpdate(recordOperate));
    }
    /**
    *  查询所有
    */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<RecordOperate> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
       List<RecordOperate> list=  recordOperateService.list(queryWrapper);
        return Result.success(list);
    }
    /**
    *  根据id查询
    */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(recordOperateService.getById(id));
    }
    /**
     *  分页查询
     */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           String keyWord,
                           String startTime,
                           String endTime) {
        pageNum = pageNum * pageSize - pageSize;
        List<RecordOperate> recordOperates = recordOperateMapper.findPage(pageNum, pageSize, keyWord, startTime, endTime);
        Long count = recordOperateMapper.findPageCount(keyWord, startTime, endTime);
        HashMap<String, Object> map = new HashMap<>();
        map.put("record", recordOperates);
        map.put("total", count);
        return Result.success(map);
    }

}

